
TAG_FINISH		equ 1024+0
TAG_BSS		equ 1024+1
TAG_BEGIN_FUNC	equ 1024+2
TAG_END_FUNC		equ 1024+3
TAG_SZ_SRC		equ 1024+4
TAG_COMPILER_ENTRY	equ 1024+5
TAG_MODULE_PATH	equ 1024+6

TAG_FIRST_TAG		equ TAG_FINISH
TAG_LAST_TAG		equ TAG_MODULE_PATH

.data

tag_pcessor_funcs_table	dd 	0,	;TAG_FINISH
				offset _@proc_BSS_tag,	;TAG_BSS
				offset _@proc_BEGIN_tag,	;TAG_BEGIN_FUNC
				offset _@proc_END_tag,	;TAG_END_FUNC
				offset _@proc_SRC_tag,	;TAG_SZ_SRC
				offset _@proc_COMPILER_tag,	;TAG_COMPILER_ENTRY
				0;offset _@proc_PATH_tag	;TAG_MODULE_PATH

.code
;----------------------------------------------------------------------------------
process_mod_bin_tags	proc lpModule
			push esi
			push edi

			mov eax,lpModule
			push eax

			push eax
			call IsThisModule
			test eax,eax
			pop esi
			jz short pmbtExit

			mov eax,dword ptr [esi+2]
			add esi,eax
			add esi,4
; skip modules part
			call ___@get_bin_mod_len
			add esi,eax

; skip relocs part
			call ___@get_bin_mod_len
			add esi,eax

	pmbtSwitcherLoop_b:
; get tag len
			call ___@get_bin_mod_len
			mov edi,eax
			add edi,esi
;get tag ID
			call ___@get_bin_mod_len

;int 3
			cmp eax,TAG_FINISH
			jz short pmbtSwitcherLoop_e

			cmp eax,TAG_LAST_TAG+1
			jnc short @f

			sub eax,TAG_FIRST_TAG
			jc short @f
			mov eax,dword ptr [tag_pcessor_funcs_table+4*eax]
			test eax,eax
			jz short @f

			push edi		;last tag data addr
			push esi		;first tag data addr
			push lpModule	;lp this module
			call eax
		@@:
			mov esi,edi
			jmp short pmbtSwitcherLoop_b
	pmbtSwitcherLoop_e:


	pmbtExit:
			pop edi
			pop esi
			ret
process_mod_bin_tags	endp
;----------------------------------------------------------------------------------
_@proc_BSS_tag	proc lpModule,lpDataFirst,lpDataLast
			push esi
			push edi
			push ebx

			mov edi,lpModule
			test edi,edi
			jz short ptExit

			mov esi,lpDataFirst
			test esi,esi
			jz short ptExit

; BSS size
			call ___@get_bin_mod_len
			test eax,eax
			jz short ptExit

			cmp lpDataLast,esi
			jc short ptExit

			mov ebx,modules_root
		assume ebx: ptr _@module_link

	module_link_seek_b:
			test ebx,ebx
			jz short ptExit

			cmp [ebx].lpModule,edi
			jz short module_link_seek_e

			mov ebx,[ebx].lpNextModule
			jmp short module_link_seek_b
	module_link_seek_e:

			push ebx

		_@getMem eax

			pop ebx
			mov [ebx].lpBSS,eax

			mov ebx,eax	;ebx=lp BSS

	BSS_fixes_check_loop_b:
			call ___@get_bin_mod_len

			cmp lpDataLast,esi
			jc short BSS_fixes_check_loop_e

printfX dword ptr [edi+eax]
			add dword ptr [edi+eax],ebx

			jmp short BSS_fixes_check_loop_b
	BSS_fixes_check_loop_e:
;int 3


	ptExit:

			pop ebx
			pop edi
			pop esi
			ret
_@proc_BSS_tag		endp
;----------------------------------------------------------------------------------
_@proc_BEGIN_tag	proc lpModule,lpDataFirst,lpDataLast
			push esi
			push edi
			push ebx

			mov edi,lpModule
			test edi,edi
			jz short ptExit

			mov esi,lpDataFirst
			test esi,esi
			jz short ptExit

; BEGIN func RVA
			call ___@get_bin_mod_len
			test eax,eax
			jz short ptExit

			add eax,edi

			cmp lpDataLast,esi
			jc short ptExit

			mov ebx,modules_root
		assume ebx: ptr _@module_link

	module_link_seek_b:
			test ebx,ebx
			jz short ptExit

			cmp [ebx].lpModule,edi
			jz short module_link_seek_e

			mov ebx,[ebx].lpNextModule
			jmp short module_link_seek_b
	module_link_seek_e:

			mov [ebx].lpBeginFunc,eax

	ptExit:

			pop ebx
			pop edi
			pop esi
			ret
_@proc_BEGIN_tag		endp
;----------------------------------------------------------------------------------
_@proc_END_tag	proc lpModule,lpDataFirst,lpDataLast
			push esi
			push edi
			push ebx

			mov edi,lpModule
			test edi,edi
			jz short ptExit

			mov esi,lpDataFirst
			test esi,esi
			jz short ptExit

; END func RVA
			call ___@get_bin_mod_len
			test eax,eax
			jz short ptExit

			add eax,edi

			cmp lpDataLast,esi
			jc short ptExit

			mov ebx,modules_root
		assume ebx: ptr _@module_link

	module_link_seek_b:
			test ebx,ebx
			jz short ptExit

			cmp [ebx].lpModule,edi
			jz short module_link_seek_e

			mov ebx,[ebx].lpNextModule
			jmp short module_link_seek_b
	module_link_seek_e:

			mov [ebx].lpEndFunc,eax

	ptExit:

			pop ebx
			pop edi
			pop esi
			ret
_@proc_END_tag		endp
;----------------------------------------------------------------------------------
_@proc_SRC_tag	proc lpModule,lpDataFirst,lpDataLast
			push esi
			push edi
			push ebx

			mov edi,lpModule
			test edi,edi
			jz short ptExit

			mov esi,lpDataFirst
			test esi,esi
			jz short ptExit

; SRC func RVA
			call ___@get_bin_mod_len
			test eax,eax
			jz short ptExit

			add eax,edi

			cmp lpDataLast,esi
			jc short ptExit

			mov ebx,modules_root
		assume ebx: ptr _@module_link

	module_link_seek_b:
			test ebx,ebx
			jz short ptExit

			cmp [ebx].lpModule,edi
			jz short module_link_seek_e

			mov ebx,[ebx].lpNextModule
			jmp short module_link_seek_b
	module_link_seek_e:
			push eax
			push ebx
		_@getMem eax
			pop ebx
			mov [ebx].lpszSrc,eax
			pop ebx
		_@cpyMem eax,esi,ebx

	ptExit:

			pop ebx
			pop edi
			pop esi
			ret
_@proc_SRC_tag		endp
;----------------------------------------------------------------------------------
_@proc_COMPILER_tag	proc lpModule,lpDataFirst,lpDataLast
			push esi
			push edi
			push ebx

			mov edi,lpModule
			test edi,edi
			jz short ptExit

			mov esi,lpDataFirst
			test esi,esi
			jz short ptExit

; COMPILER func RVA
			call ___@get_bin_mod_len
			test eax,eax
			jz short ptExit

			add eax,edi

			cmp lpDataLast,esi
			jc short ptExit

			mov ebx,modules_root
		assume ebx: ptr _@module_link

	module_link_seek_b:
			test ebx,ebx
			jz short ptExit

			cmp [ebx].lpModule,edi
			jz short module_link_seek_e

			mov ebx,[ebx].lpNextModule
			jmp short module_link_seek_b
	module_link_seek_e:

			mov [ebx].lpCompilFunc,eax

;			call ___@get_bin_mod_len
;			test eax,eax
;			jz short ptExit
;
;			push eax
;			push ebx
;		_@getMem eax
;			pop ebx
;			mov [ebx].lpszCompilName,eax
;			pop ebx
;		_@cpyMem eax,esi,ebx

	ptExit:

			pop ebx
			pop edi
			pop esi
			ret
_@proc_COMPILER_tag		endp
;----------------------------------------------------------------------------------
_@proc_PATH_tag	proc lpModule,lpDataFirst,lpDataLast
			push esi
			push edi
			push ebx

			mov edi,lpModule
			test edi,edi
			jz short ptExit

			mov esi,lpDataFirst
			test esi,esi
			jz short ptExit

; PATH func RVA
			call ___@get_bin_mod_len
			test eax,eax
			jz short ptExit

			add eax,edi

			cmp lpDataLast,esi
			jc short ptExit

			mov ebx,modules_root
		assume ebx: ptr _@module_link

	module_link_seek_b:
			test ebx,ebx
			jz short ptExit

			cmp [ebx].lpModule,edi
			jz short module_link_seek_e

			mov ebx,[ebx].lpNextModule
			jmp short module_link_seek_b
	module_link_seek_e:
			push eax
			push ebx
		_@getMem eax
			pop ebx
			mov [ebx].lpszPath,eax
			pop ebx
		_@cpyMem eax,esi,ebx

	ptExit:

			pop ebx
			pop edi
			pop esi
			ret
_@proc_PATH_tag	endp
;----------------------------------------------------------------------------------
;_@proc__tag	proc lpModule,lpDataFirst,lpDataLast
;			push esi
;			push edi
;			mov esi,lpModule
;			test esi,esi
;			jz short ptExit
;
;	ptExit:
;			pop edi
;			pop esi
;			ret
;_@proc__tag		end
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------
;----------------------------------------------------------------------------------

